﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace FYP14
{
    public partial class PopupPatient : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SetInitialRow();
            }
        }

        private void SetInitialRow()
        {
            DataTable dt = BAL.GetAllPatients();
            ViewState["Savedt"] = dt;
            gvPurchase.DataSource = dt;
            gvPurchase.DataBind();
        }

        protected void gvPurchase_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

            }
        }

        protected void lnkRemove_Click(object sender, EventArgs e)
        {
            ImageButton lb = (ImageButton)sender;
            DataTable dt = BAL.GetPatient(Convert.ToInt32(lb.CommandArgument));
            Patient oPatient = new Patient();
            if (dt.Rows.Count > 0)
            {
                oPatient.ID = Convert.ToInt32(dt.Rows[0]["patient_id"]);
                oPatient.Name = dt.Rows[0]["name"].ToString();
            }
            string radalertscript = "<script language='javascript'>window.opener.updateFromChildWindow(" + oPatient.ID + ", '" + oPatient.Name + "');    window.close();     window.opener.focus();</script>";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "radalert", radalertscript);
        }

        protected void gvPurchase_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvPurchase.PageIndex = e.NewPageIndex;
            DataTable dt = new DataTable();
            if (ViewState["Savedt"] != null)
            {
                dt = (DataTable)ViewState["Savedt"];
            }
            else
            {
                dt = BAL.GetAllPatients();
                ViewState["Savedt"] = dt;
            }
            gvPurchase.DataSource = dt;
            gvPurchase.DataBind();
        }
    }
}